#ifndef PSFRun_h
#define PSFRun_h 1

#include "G4Run.hh"

class PSFRun : public G4Run
{
public:
  PSFRun() = default;
  ~PSFRun() override = default;

  void AddTIR(G4int n)
  {
    G4double nd(n);
    fNTIR += nd;
    fNTIR2 += nd * nd;
  };
  void AddExiting(G4int n)
  {
    G4double nd(n);
    fNExiting += nd;
    fNExiting2 += nd * nd;
  };
  void AddEscapedEnd(G4int n)
  {
    G4double nd(n);
    fEscapedEnd += nd;
    fEscapedEnd2 += nd * nd;
  };
  void AddEscapedMid(G4int n)
  {
    G4double nd(n);
    fEscapedMid += nd;
    fEscapedMid2 += nd * nd;
  };
  void AddBounce(G4int n)
  {
    G4double nd(n);
    fBounce += nd;
    fBounce2 += nd * nd;
  };
  void AddPSFCoreBounce(G4int n)
  {
    G4double nd(n);
    fPSFCoreBounce += nd;
    fPSFCoreBounce2 += nd * nd;
  };
  void AddClad1Bounce(G4int n)
  {
    G4double nd(n);
    fClad1Bounce += nd;
    fClad1Bounce2 += nd * nd;
  };
  void AddClad2Bounce(G4int n)
  {
    G4double nd(n);
    fClad2Bounce += nd;
    fClad2Bounce2 += nd * nd;
  };
  void AddReflected(G4int n)
  {
    G4double nd(n);
    fReflected += nd;
    fReflected2 += nd * nd;
  };
  void AddEscaped(G4int n)
  {
    G4double nd(n);
    fEscaped += nd;
    fEscaped2 += nd * nd;
  };
  void AddMirror(G4int n)
  {
    G4double nd(n);
    fMirror += nd;
    fMirror2 += nd * nd;
  };
  void AddDetectorHits(G4int n)
  {
    G4double nd(n);
    fDetectorHits += nd;
    fDetectorHits2 += nd * nd;
  };
  void AddCoreTIR(G4int n)
  {
    G4double nd(n);
    fCoreTIR += nd;
    fCoreTIR2 = fCoreTIR * fCoreTIR;
  };
  void AddCoreR(G4int n)
  {
    G4double nd(n);
    fCoreR += nd;
    fCoreR2 = fCoreR * fCoreR;
  };
  void AddClad1TIR(G4int n)
  {
    G4double nd(n);
    fClad1TIR += nd;
    fClad1TIR2 = fClad1TIR * fClad1TIR;
  };
  void AddClad1R(G4int n)
  {
    G4double nd(n);
    fClad1R += nd;
    fClad1R2 = fClad1R * fClad1R;
  };
  void AddCoupleR(G4int n)
  {
    G4double nd(n);
    fCoupleR += nd;
    fCoupleR2 = fCoupleR * fCoupleR;
  };

  void BeginOfRun();
  void EndOfRun();
  void Merge(const G4Run *) override;

private:
  G4double fNTIR = 0.;
  G4double fNTIR2 = 0.;
  G4double fNExiting = 0.;
  G4double fNExiting2 = 0.;
  G4double fEscapedEnd = 0.;
  G4double fEscapedEnd2 = 0.;
  G4double fEscapedMid = 0.;
  G4double fEscapedMid2 = 0.;
  G4double fBounce = 0.;
  G4double fBounce2 = 0.;
  G4double fPSFCoreBounce = 0.;
  G4double fPSFCoreBounce2 = 0.;
  G4double fClad1Bounce = 0.;
  G4double fClad1Bounce2 = 0.;
  G4double fClad2Bounce = 0.;
  G4double fClad2Bounce2 = 0.;
  G4double fReflected = 0.;
  G4double fReflected2 = 0.;
  G4double fEscaped = 0.;
  G4double fEscaped2 = 0.;
  G4double fMirror = 0.;
  G4double fMirror2 = 0.;
  G4double fDetectorHits = 0.;
  G4double fDetectorHits2 = 0.;

  G4double fCoreTIR = 0.;
  G4double fCoreTIR2 = 0.;
  G4double fCoreR = 0.;
  G4double fCoreR2 = 0.;
  G4double fClad1TIR = 0.;
  G4double fClad1TIR2 = 0.;
  G4double fClad1R = 0.;
  G4double fClad1R2 = 0.;
  G4double fCoupleR = 0.;
  G4double fCoupleR2 = 0.;
};

#endif
